package com.dankegongyu.component.loadingcontroller.sample;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import com.dankegongyu.component.loadingcontroller.LoadingController;
import com.dankegongyu.component.loadingcontroller.LoadingInterface;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @author wupuquan
 * @version 1.0
 * @since 2018/4/3 13:59
 */
public class MainActivity extends AppCompatActivity {

    private TextView mTvTest1;
    private LoadingController mLoadingController1;

    private TextView mTvTest2;
    private LoadingController mLoadingController2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTvTest1 = findViewById(R.id.tv_test1);
        mTvTest1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLoading1();
            }
        });
        mLoadingController1 = AppLoadingController.create(mTvTest1)
                .setBgColor(Color.RED)
                .setOnErrorRetryClickListener(new LoadingInterface.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        showEmpty1();
                    }
                })
                .setOnEmptyTodoClickListener(new LoadingInterface.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mLoadingController1.showTarget();
                    }
                });


        mTvTest2 = findViewById(R.id.tv_test2);
        mTvTest2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLoading2();
            }
        });
        mLoadingController2 = AppLoadingController.create(mTvTest2, new LoadingConfig2())
                .setOnErrorRetryClickListener(new LoadingInterface.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        showEmpty2();
                    }
                })
                .setOnEmptyTodoClickListener(new LoadingInterface.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mLoadingController2.showTarget();
                    }
                });
    }

    private void showLoading1() {
        mLoadingController1.showLoading();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mLoadingController1.showError();
//                mLoadingController.showError("我的是我的，你的还是我的~");
//                mLoadingController.showError("看尔乃插标卖首！", false);
//                mLoadingController.showError("尔等敢应战否？", "全军突击");
//
//                TextView custom = new TextView(MainActivity.this);
//                custom.setTextColor(Color.RED);
//                custom.setText("吾乃常山赵子龙也！");
//                custom.setGravity(Gravity.CENTER);
//                custom.setPadding(50, 50, 50, 50);
//                mLoadingController.showError(custom);
            }
        }, 1500);
    }

    private void showEmpty1() {
        mLoadingController1.showLoading();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
//                mLoadingController.showEmpty();
//                mLoadingController.showEmpty("观今夜天象，知天下大事~");
                mLoadingController1.showEmpty("暂无数据", "去看房");
//                mLoadingController.showEmpty(R.mipmap.ic_launcher, "将星陨落，天命难违。。");
//                mLoadingController.showEmpty(R.mipmap.ic_launcher, "吾通晓兵法，世人皆知~", "雕虫小技");
//                mLoadingController.showEmpty(getResources().getDrawable(R.mipmap.ic_launcher_round), "千秋万载，一统江山！");
//                mLoadingController.showEmpty(getResources().getDrawable(R.mipmap.ic_launcher_round), "仙福永享，寿与天齐！", "主公，快走！");
//
//                ImageView imageView = new ImageView(MainActivity.this);
//                imageView.setImageResource(R.mipmap.ic_launcher_round);
//                mLoadingController.showEmpty(imageView);
            }
        }, 1500);
    }

    private void showLoading2() {
        mLoadingController2.showLoading(R.drawable.loading_anim_list);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mLoadingController2.showError();
//                mLoadingController.showError("我的是我的，你的还是我的~");
//                mLoadingController.showError("看尔乃插标卖首！", false);
//                mLoadingController.showError("尔等敢应战否？", "全军突击");
//
//                TextView custom = new TextView(MainActivity.this);
//                custom.setTextColor(Color.RED);
//                custom.setText("吾乃常山赵子龙也！");
//                custom.setGravity(Gravity.CENTER);
//                custom.setPadding(50, 50, 50, 50);
//                mLoadingController.showError(custom);
            }
        }, 1500);
    }

    private void showEmpty2() {
        mLoadingController2.showLoading(R.mipmap.ic_launcher);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
//                mLoadingController.showEmpty();
//                mLoadingController.showEmpty("观今夜天象，知天下大事~");
                mLoadingController2.showEmpty("暂无数据", "去看房");
//                mLoadingController.showEmpty(R.mipmap.ic_launcher, "将星陨落，天命难违。。");
//                mLoadingController.showEmpty(R.mipmap.ic_launcher, "吾通晓兵法，世人皆知~", "雕虫小技");
//                mLoadingController.showEmpty(getResources().getDrawable(R.mipmap.ic_launcher_round), "千秋万载，一统江山！");
//                mLoadingController.showEmpty(getResources().getDrawable(R.mipmap.ic_launcher_round), "仙福永享，寿与天齐！", "主公，快走！");
//
//                ImageView imageView = new ImageView(MainActivity.this);
//                imageView.setImageResource(R.mipmap.ic_launcher_round);
//                mLoadingController.showEmpty(imageView);
            }
        }, 1500);
    }
}
